{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 我们这里一般的单张图片没有批量和通道\n",
    "def conv2d_2d(conv2d, x:torch.Tensor):\n",
    "    x = x.reshape((1,1)+x.shape)\n",
    "    # print(x.shape)\n",
    "    y = conv2d(x)\n",
    "    # print(y.shape)\n",
    "    return y.reshape(y.shape[2:])\n",
    "\n",
    "conv2d = torch.nn.Conv2d(1,1,(3,3),padding=(1,2),stride=2) # 上下左右各填充1，步长是2  2+2 -3 +1 = 2   2/2 = 1\n",
    "x = torch.zeros((2,2),dtype=torch.float32)\n",
    "# print(x.shape)\n",
    "y = conv2d_2d(conv2d,x)\n",
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 池化\n",
    "torch.nn.MaxPool2d(kernel_size=(3,3),stride=(1,1),padding=(1,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 多输入单输出\n",
    "# def mul_intosin_out(X,K):\n",
    "#     return sum(torch.nn.Conv2d(1,1,channal,k) for channal,k in zip(X,K))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# a = torch.tensor([\n",
    "#         [[1,1,1],\n",
    "#         [1,1,1]],\n",
    "\n",
    "#         [[2,2,2],\n",
    "#         [2,2,2]]\n",
    "#         ])\n",
    "# k = torch.tensor([\n",
    "#     [[1,1]],\n",
    "#     [[1,1]],\n",
    "# ])\n",
    "# print(mul_intosin_out(a,k))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
